from fastapi import APIRouter, Request
from utils import create_json_response
import json

router = APIRouter()

@router.post("/app/list")
async def get_app_list(request: Request):
    """应用列表路由 - 返回分组的应用列表数据"""
    
    # 读取原始数据流（支持数据流格式）
    body = await request.body()
    
    # 应用列表数据，按分组组织
    app_list = [
        {
            "name": "客户管理",
            "apps": [
                {
                    "name": "客户列表",
                    "icon": "group-line",
                    "url": "https://weui.io/"
                },
                {
                    "name": "新增客户",
                    "icon": "user-add-line",
                    "url": "https://******.com/"
                },
                {
                    "name": "客户分析",
                    "icon": "chat-1-line",
                    "url": "https://******/__UNI__5123B68.wgt"
                }
            ]
        },
        {
            "name": "销售管理",
            "apps": [
                {
                    "name": "订单管理",
                    "icon": "chat-forward-line",
                    "url": "app://one"
                },
                {
                    "name": "销售报表",
                    "icon": "chat-smile-3-line",
                    "url": "app://two"
                },
                {
                    "name": "销售预测",
                    "icon": "chat-quote-line",
                    "url": "https://******.com/"
                },
                {
                    "name": "营销活动",
                    "icon": "edit-box-line",
                    "url": "app://two@to/pages/party/index"
                },
                {
                    "name": "邮件营销",
                    "icon": "contrast-2-line",
                    "url": "https://******/__UNI__A12902A.wgt?cache=0"
                }
            ]
        },
        {
            "name": "系统管理",
            "apps": [
                {
                    "name": "用户管理",
                    "icon": "artboard-line",
                    "url": "https://******/__UNI__USER.wgt"
                },
                {
                    "name": "权限设置",
                    "icon": "clockwise-2-line",
                    "url": "app://admin"
                },
                {
                    "name": "系统监控",
                    "icon": "layout-bottom-2-line",
                    "url": "https://******/monitor"
                }
            ]
        },
        {
            "name": "财务管理",
            "apps": [
                {
                    "name": "财务报表",
                    "icon": "flip-vertical-line",
                    "url": "https://******/__UNI__FINANCE.wgt"
                },
                {
                    "name": "收支统计",
                    "icon": "bug-line",
                    "url": "app://finance"
                },
                {
                    "name": "发票管理",
                    "icon": "git-close-pull-request-line",
                    "url": "https://******/invoice"
                }
            ]
        }
    ]
    
    return create_json_response(app_list)
